<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String contextPath = application.getContextPath();
	application.setAttribute("path", contextPath);
%>    
﻿<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="common_header.jsp" flush="true"></jsp:include>
<link href="${path }/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<title>后台登录 - JBase v0.1</title>
</head>
<body>
<input type="hidden" id="TenantId" name="TenantId" value="" />
<div class="header"></div>
<div class="loginWraper">
  <div id="loginform" class="loginBox">
    <form class="form form-horizontal" action="index.html" method="post">
      <div class="row cl">
        <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
        <div class="formControls col-xs-8">
          <input id="username" name="" type="text" onkeydown="toLogin(event)" placeholder="账户" class="input-text size-L">
        </div>
      </div>
      <div class="row cl">
        <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
        <div class="formControls col-xs-8">
          <input id="password" name="" type="password" onkeydown="toLogin(event)" placeholder="密码" class="input-text size-L">
        </div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-3">
          <input class="input-text size-L" id="captcha" name="captcha" type="text" placeholder="验证码" onkeydown="toLogin(event)" style="width:150px;">
          <img src="${path }/user/captcha.do" id="captchaImg"> <a id="kanbuq" href="javascript:refreshCaptcha();">看不清，换一张</a> </div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-3">
          <label for="rememberMe">
            <input type="checkbox" name="online" id="rememberMe" value="">
             使我保持登录状态</label> <span id="loginMsg" style="color: yellow;"></span>
        </div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-3">
          <input name="" type="button" id="loginBtn" onclick="loginSys()" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">
          <input name="" type="reset" class="btn btn-default radius size-L" value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
        </div>
      </div>
    </form>
  </div>
</div>
<div class="footer">Copyright iBASE PRO by JBase v0.1</div>
<script type="text/javascript" src="${path }/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${path }/static/h-ui/js/H-ui.min.js"></script>
<%-- <script type="text/javascript" src="${path}/static/h-ui/js/H-ui.js"></script> --%>
<script>

$(function(){
	var uname = $.cookie('username');
	var pwd = $.cookie('password');
	var rememberMe = $.cookie('rememberMe');
	
	if (rememberMe == 1) {
		$('#rememberMe').attr('checked', 'checked');
		if (uname && uname != 'null') {
			$('#username').val(uname);
		}
		if (pwd && pwd != 'null') {
			$('#password').val(pwd);
		}
	}
});

function toLogin(e) {
	var ev = document.all ? window.event : e;
	if (ev.keyCode == 13) {
		$('#loginBtn').click();
	}
}

function loginSys(){
	$('#loginBtn').prop("disable",true);
	
	var username = $.trim($('#username').val());
	var password = $.trim($('#password').val());
	var captcha = $.trim($('#captcha').val());
	if (username == '') {
		alert("请输入用户名");
		return;
	}
	if (password == '') {
		alert("请输入密码");
		return;
	}
	if (captcha == '') {
		alert("请输入验证码");
		return;
	}
	
	$('#loginMsg').text('正在登陆...');
	
	$.ajax({
		url: "${path}/user/login.do",
		data: 'username='+username+'&password='+password+'&captcha='+captcha, 
		type: "POST",
		success: function(data, textStatus){
			if (data.code == 0) {
				$('#loginMsg').text('登陆成功,正在跳转...');
				var checked = $('#rememberMe').prop('checked');
				
				if (checked) {
					$.cookie('username', username, { expires: 7, path: '/' });
					$.cookie('password', password, { expires: 7, path: '/' });
					$.cookie('rememberMe', 1, { expires: 7, path: '/' });
				} else {
					$.cookie('username', null);
					$.cookie('password', null);
					$.cookie('rememberMe', 0, { expires: 7, path: '/' });
				}
				window.location.href = "${path}/user/toPage.do?page=index";
			}else{
				$('#loginMsg').text('');
				$('#loginBtn').prop("disable",false);
				alert(data.msg);
			}
		},
		error: function (data, textStatus, errorThrown) {
			var s=JSON.stringify(data);
			//console.log(s);
		}
	});		
	
}

function refreshCaptcha(){
	$('#captchaImg').attr('src', '${path}/user/captcha.do?v='+Math.random());
}
</script>
</body>
</html>
